package com.itheima70.googleplay.util;

import android.R.anim;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

public class DrawableUtil {
	/**
	 * 动态创建shape图形
	 * @return
	 */
	public static GradientDrawable generateDrawable(int argb,float radius){
		GradientDrawable drawable = new GradientDrawable();
		drawable.setShape(GradientDrawable.RECTANGLE);//设置形状为矩形,默认也是矩形
		drawable.setCornerRadius(radius);//设置4个角的角度
		drawable.setColor(argb);//设置图片的填充颜色
		return drawable;
	}
	
	/**
	 * 动态生成selector
	 * @return
	 */
	public static StateListDrawable generateSelector(Drawable pressed,Drawable normal){
		StateListDrawable drawable = new StateListDrawable();
		drawable.addState(new int[]{android.R.attr.state_pressed}, pressed);//设置按下状态对应的图片
		drawable.addState(new int[]{}, normal);//设置默认的图片
		return drawable;
	}
}
